<template>
	<view class="">
		<view class="nav_top-bg">
			<u-navbar title="我的余额">
				<view class="u-nav-slot" slot="left">
					<u-icon name="arrow-left" @click="go_black" size="19"></u-icon>
					<u-line direction="column" :hairline="false" length="16" margin="0 10px"></u-line>
					<u-icon name="home" @click="goHome" size="20"></u-icon>
				</view>
			</u-navbar>
		</view>
		<!-- 选择平台 -->
		<view class="pingtai d-flex">
			<view class="u-radio-w d-flex">
				<u-radio-group v-model="radiovalue1" placement="row">
					<u-radio activeColor="#40AE36" :customStyle="{marginRight: '20rpx'}" v-for="(item, index) in radiolist1" :key="index"
						:label="item.name" :name="item.id" @change="radioChange">
					</u-radio>
				</u-radio-group>
			</view>
		</view>
		<!-- 选择提现到银行卡 -->
		<view class="kaihuhang" v-if="radiovalue1 == 0">
			<view class="avatar">
				<text class="touxtxt">开户行</text>
				<view class="righttx">
					<input class="ipt" type="text" placeholder="请输入开户行" v-model="kaihuhang">
				</view>
			</view>
			<view class="avatar">
				<text class="touxtxt">银行卡号</text>
				<view class="righttx">
					<input class="ipt" type="text" placeholder="请输入" v-model="card">
				</view>
			</view>
			<view class="avatar">
				<text class="touxtxt">持卡人姓名</text>
				<view class="righttx">
					<input class="ipt" type="text" placeholder="请输入" v-model="card_name">
				</view>
			</view>
		</view>
		<!-- 选择提现到微信 -->
		<view class="kaihuhang" v-if="radiovalue1 == 1">
			<view class="w-630">
				<view class="skm">收款码</view>
				<view class="adress_suozai">
					<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
						:maxCount="1">
						<image :src="src" class="shangchuanimg" v-if="avatar"></image>
						<image src="../static/upload.png" class="shangchuanimg" v-else></image>
					</u-upload>
				</view>
				<view class="wechatimg">请上传微信收款码</view>
				<view class="avatar">
					<text class="touxtxt">收款人姓名</text>
					<view class="righttx">
						<input class="ipt" type="text" placeholder="请输入" v-model="shoukuanren_name">
					</view>
				</view>
			</view>
		</view>
		<!-- 选择提现到支付宝 -->
		<view class="kaihuhang" v-if="radiovalue1 == 2">
			<view class="avatar">
				<text class="touxtxt">支付宝账号</text>
				<view class="righttx">
					<input class="ipt" type="text" placeholder="请输入支付宝账号" v-model="zhifubao_card">
				</view>
			</view>
			<view class="avatar">
				<text class="touxtxt">姓名</text>
				<view class="righttx">
					<input class="ipt" type="text" placeholder="请输入" v-model="pay_name">
				</view>
			</view>
		</view>
		<!-- 发起提现按钮 -->
		<view class="foot-tixian">
			<view class="foot_btn-but">
				<u-button text="提现" size="large" shape="circle" @click="tixian_go" color="#FF6400"></u-button>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {
		upFile
	} from '@/utils/url.js'
	import {usertixian} from '@/api/user.js'
	export default {
		data() {
			return {
				fileList1:[],
				avatar: '',
				src: require('../static/upload.png'),
				radiolist1: [{
						name: '提现到银行卡',
						id: 0,
						disabled: false
					},
					{
						name: '提现到微信',
						id: 1,
						disabled: false
					},
					{
						name: '提现到支付宝',
						id: 2,
						disabled: false
					}
					
				],
				radiovalue1: 0,
				kaihuhang:'',
				card:'',
				card_name:'',
				shoukuanren_name:'',
				zhifubao_card:'',
				pay_name:'',
				money:'',
			}
		},
		onLoad(option) {
			this.money = option.money_num
		},
		methods: {
			go_black() {
				uni.navigateBack({
					delta: 1
				})
			},
			goHome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			radioChange(n) {
				console.log('radioChange', n);
				this.radiovalue1 = n
			},
			tixian_go() {
				var data = {
					paytype: this.radiovalue1,
					jine: this.money,
					bank_zhanghao: this.card,
					bank_name: this.card_name,
					bank_id: this.kaihuhang,
					alipay_zhanghao: this.zhifubao_card,
					alipay_name: this.pay_name,
					wxpay_image: this.fileList1.length ? this.fileList1[0].url_noyuming : '',
				}
				usertixian(data).then(res => {
					console.log("提现是否成功",res);
					if(res.code == 1){
						uni.showToast({
							title:'提现成功',
							icon:'success'
						})
						setTimeout(() => {
							if (typeof this.$util.prePage().get_userdetail == 'function') {
								this.$util.prePage().get_userdetail()
							}
							uni.navigateBack({
								delta: 1
							})
						},500)
						
					}
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				var url = event.file[0].url
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				console.log("00000000000000", lists);
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						fullurl: result.fullurl,
						url_noyuming: result.url
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				var that = this
				console.log("url有没有值", url);
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: upFile,
						filePath: url,
						name: 'file',
						formData: {
							user: 'test',
							token: uni.getStorageSync('token')
						},
						success: (res) => {
							console.log("s111111111111111______", res);
							var data = JSON.parse(res.data);
							resolve(data.data)
						}
					});
				})
			},
		}
	}
</script>

<style>
	.wechatimg{
		font-size: 24rpx;
		font-weight: normal;
		color: #A9A9A9;
		line-height: 50rpx;
	}
	.skm{
		font-size: 30rpx;
		font-weight: normal;
		color: #333333;
		margin-bottom: 30rpx;
	}
	.shangchuanimg {
		width: 200rpx;
		height: 200rpx;
		border: 1px solid #eee;
		display: block;
		margin: auto;
		overflow: hidden;
	}
	.ipt {
		font-size: 30rpx;
		font-weight: normal;
		text-align: right;
		color: #333333;
	}
	
	.touxtxt {
		font-size: 30rpx;
		font-weight: normal;
		display: block;
		color: #333333;
	}
	.foot-tixian{
		width: 750rpx;
		position: fixed;
		bottom: 68rpx;
	}
	
	.foot_btn-but{
		width: 690rpx;
		margin: auto;
	}
	
	.avatar {
		width: 630rpx;
		border-bottom: 1px solid #f5f5f5;
		height: 110rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: auto;
	}
	.kaihuhang{
		width: 690rpx;
		padding: 40rpx 0;
		background-color: #fff;
		border-radius: 20rpx;
		margin: 30rpx auto;
	}
	.u-radio-w{
		width: 700rpx;
		margin: auto;
		flex-wrap: wrap;
	}
	.pingtai {
		width: 750rpx;
		height: 122rpx;
		background-color: #fff;
		border-radius: 20rpx;
		margin: 30rpx auto;
	}

	page {
		background-color: #F7F8FB;
	}
</style>